package com.itheima.wisdomnext.mapper;

import com.itheima.wisdomnext.entity.QaPost;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface QaPostMapper {

    // 插入问答帖子
    @Insert("INSERT INTO qa_posts (question_userid, question_title, question_type, category_id) " +
            "VALUES (#{questionUserId}, #{questionTitle}, #{questionType}, #{categoryId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")  // 确保返回自增 ID
    void insertQaPost(QaPost qaPost);

    // 根据 ID 查询问答帖子
    @Select("SELECT * FROM qa_posts WHERE id = #{id}")
    QaPost selectQaPostById(int id);
}
